<template>
  <div class="wrapper">
  <!--绑定数据，记得在data中接收，因为是子组件，data必须是函数，这里是es6的写法-->
  <swiper :options="swiperOption" v-if="showSwiper">
    <swiper-slide v-for="item of list" :key="item.id">
      <!--src与item.imgUrl进行数据绑定-->
      <img class="swiper-img" :src="item.imgUrl"/>
    </swiper-slide>
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true // 使得可以左右循环
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background :#ffffff !important
  .wrapper
    overflow :hidden
    width :100%
    height :0
    padding-bottom :31.25%
  .swiper-img
     width :100%
</style>
